Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: faster tick for snapshot #8427

Closed
wants to merge 2 commits into from
Closed

perf: faster tick for snapshot #8427

wants to merge 2 commits into from

Conversation

doodlewind
Copy link
Member

@doodlewind doodlewind commented Sep 21, 2024

This tries to optimize #8380

@doodlewind doodlewind requested a review from a team as a code owner September 21, 2024 13:04
Copy link

vercel bot commented Sep 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 21, 2024 3:05pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Sep 21, 2024 3:05pm

Copy link

changeset-bot bot commented Sep 21, 2024

⚠️ No Changeset found

Latest commit: 300fe2c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

graphite-app bot commented Sep 21, 2024

Your org has enabled the Graphite merge queue for merging into master

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link

nx-cloud bot commented Sep 21, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 300fe2c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link
Contributor

github-actions bot commented Sep 21, 2024

size-limit report 📦

Path Size
@blocksuite/affine 13 B (0%)
@blocksuite/affine/effects 2.03 MB (+0.03% 🔺)
@blocksuite/affine/block-std 145.04 KB (+0.09% 🔺)
@blocksuite/affine/block-std/gfx 75.93 KB (0%)
@blocksuite/affine/global 13 B (0%)
@blocksuite/affine/global/utils 14.11 KB (+2.1% 🔺)
@blocksuite/affine/global/env 231 B (0%)
@blocksuite/affine/global/exceptions 552 B (0%)
@blocksuite/affine/global/di 1.65 KB (0%)
@blocksuite/affine/global/types 13 B (0%)
@blocksuite/affine/store 69.2 KB (+0.16% 🔺)
@blocksuite/affine/inline 30.43 KB (-0.08% 🔽)
@blocksuite/affine/inline/consts 51 B (0%)
@blocksuite/affine/inline/types 13 B (0%)
@blocksuite/affine/presets 1.83 MB (+0.01% 🔺)
@blocksuite/affine/blocks 1.92 MB (+0.01% 🔺)
@blocksuite/affine/blocks/schemas 85.48 KB (0%)

@fourdim
Copy link
Contributor

fourdim commented Sep 21, 2024

I do think it's much better to add a parameter in this function.
RequestIdleCallback will schedule the task to a not near future compared to promise.resolve, if I remember correctly.

@doodlewind doodlewind closed this Sep 21, 2024
@doodlewind
Copy link
Member Author

doodlewind commented Sep 21, 2024

@fourdim queueMicrotask could be much faster (but jams the UI). I'm just not sure why we make async loading by default.

function testNextTick(useRequestIdleCallback, iterations = 1000) {
  const nextTick = useRequestIdleCallback
    ? (callback) => requestIdleCallback(() => callback())
    : (callback) => queueMicrotask(() => callback());

  return new Promise((resolve) => {
    const startTime = performance.now();
    let count = 0;

    function runIteration() {
      if (count < iterations) {
        nextTick(() => {
          count++;
          runIteration();
        });
      } else {
        const endTime = performance.now();
        resolve(endTime - startTime);
      }
    }

    runIteration();
  });
}

async function runTest() {
  console.log('Starting performance test...');

  const rICTime = await testNextTick(true);
  console.log(`requestIdleCallback: ${rICTime.toFixed(2)}ms`);

  const qMTTime = await testNextTick(false);
  console.log(`queueMicrotask: ${qMTTime.toFixed(2)}ms`);

  const difference = Math.abs(rICTime - qMTTime);
  const fasterMethod = rICTime < qMTTime ? 'requestIdleCallback' : 'queueMicrotask';

  console.log(`\nDifference: ${difference.toFixed(2)}ms`);
  console.log(`${fasterMethod} is faster in this test.`);
}

runTest();
requestIdleCallback: 63213.20ms
queueMicrotask: 4.10ms

@fourdim
Copy link
Contributor

fourdim commented Sep 21, 2024

We won't jam the UI becuase we have batch import function which reserves the time for UI to response.

@doodlewind
Copy link
Member Author

We won't jam the UI becuase we have batch import function which reserves the time for UI to response.

Here is also the code path when pasting very long content, see #7796

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants